From: Julian Sparber Date: Tue, 13 Feb 2024 18:25:57 +0000 (+0100) Subject: messageTray: Add object holding sound for a notification X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~281^2~1^2~32 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=e4c44fd1eda1e624d2728251234c8c508fb709c0;p=gnome-shell.git messageTray: Add object holding sound for a notification A notification can have two ways to specify a sound, via a name of a sound in the sound theme and/or a file. Therefore introduce an object that can hold both properties and creates an abstraction over the different source. This reduces the number of properties for a notification, which will make it simpler to port it to GObject properties. Part-of: --- diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js index 8e1d1ed10..c0d7c4a73 100644 --- a/js/ui/messageTray.js +++ b/js/ui/messageTray.js @@ -314,6 +314,25 @@ export const NotificationApplicationPolicy = GObject.registerClass({ } }); +export const Sound = GObject.registerClass( +class Sound extends GObject.Object { + constructor(file, themedName) { + super(); + + this._soundFile = file; + this._soundName = themedName; + } + + play() { + const player = global.display.get_sound_player(); + + if (this._soundName) + player.play_from_theme(this._soundName, _('Notification sound'), null); + else if (this._soundFile) + player.play_from_file(this._soundFile, _('Notification sound'), null); + } +}); + // Notification: // @source: the notification's Source // @title: the title @@ -391,8 +410,7 @@ export const Notification = GObject.registerClass({ this.forFeedback = false; this.bannerBodyText = null; this.bannerBodyMarkup = false; - this._soundName = null; - this._soundFile = null; + this.sound = null; this._soundPlayed = false; this.actions = []; this.setResident(false); @@ -419,8 +437,7 @@ export const Notification = GObject.registerClass({ bannerMarkup: false, clear: false, datetime: null, - soundName: null, - soundFile: null, + sound: null, }); this.title = title; @@ -438,10 +455,8 @@ export const Notification = GObject.registerClass({ if (params.clear) this.actions = []; - if (this._soundName !== params.soundName || - this._soundFile !== params.soundFile) { - this._soundName = params.soundName; - this._soundFile = params.soundFile; + if (this.sound !== params.sound) { + this.sound = params.sound; this._soundPlayed = false; } @@ -495,11 +510,7 @@ export const Notification = GObject.registerClass({ return; } - let player = global.display.get_sound_player(); - if (this._soundName) - player.play_from_theme(this._soundName, this.title, null); - else if (this._soundFile) - player.play_from_file(this._soundFile, this.title, null); + this.sound?.play(this.title); } // Allow customizing the banner UI: diff --git a/js/ui/notificationDaemon.js b/js/ui/notificationDaemon.js index 09c1c6b18..a47e09860 100644 --- a/js/ui/notificationDaemon.js +++ b/js/ui/notificationDaemon.js @@ -204,8 +204,7 @@ class FdoNotificationDaemon { gicon, bannerMarkup: true, clear: true, - soundFile, - soundName: hints['sound-name'], + sound: new MessageTray.Sound(soundFile, hints['sound-name']), }); let hasDefaultAction = false;